package com.yimi.policyservice.service.impl;

import com.yimi.policyservice.entity.base.system.SysUserDataPermission;
import com.yimi.policyservice.repository.UserDataPermissionRepository;
import com.yimi.policyservice.service.UserDataPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserDataPermissionServiceImpl implements UserDataPermissionService {
    @Autowired
    private UserDataPermissionRepository userDataPermissionRepository;
    @Override
   public int addDataPermission(String userId,String dataValue,Integer dataType){
        List<String> userPermissions = userDataPermissionRepository.findUserPermissions(userId, dataValue, dataType);
        if(userPermissions.isEmpty()){
            SysUserDataPermission userDataPermission =new SysUserDataPermission();
            userDataPermission.setUserId(userId);
            userDataPermission.setCreateId(userId);
            userDataPermission.setDataType(dataType);
            userDataPermission.setDataValue(dataValue);
            userDataPermission.setCreateTime(new Date());
            userDataPermissionRepository.save(userDataPermission);
            return 1;
        }else{
            return 0;
        }

    }
}
